import { Module,NestModule,MiddlewareConsumer, RequestMethod } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm'; 
import { Connection } from 'typeorm'; 
import { AllExceptionsFilter } from './error/exception.filter';

// import { CatsModule } from './cats/cats.module';
import { User } from './entity';
import { APP_FILTER } from '@nestjs/core';
import { UserInfoMiddleware } from './middleware/userinfo.middleware';

import { UserModule } from './user/user.module';
import { LuckyModule } from './luck/luck.module';
import { SignModule } from './sign/sign.module';
// const ENTITIES = [User];
@Module({
  providers: [
    {
      provide: APP_FILTER,
      useClass:AllExceptionsFilter
    },
  ],
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: '123456',
      database: 'sheila',
      entities: ['src/entity/**/*.entity{.ts,.js}'],
      synchronize: true,
    }),
    UserModule,
    LuckyModule,
    SignModule,
    // CatsModule,
    // TypeOrmModule.forFeature([...ENTITIES])
  ],
  // controllers: [AppController],
  // providers: [AppService],
})
  
// export class AppModule implements NestModule {
//   // constructor(private readonly connection: Connection) {}
//   configure(consumer: MiddlewareConsumer) {
//     consumer
//       .apply(UserInfoMiddleware)
//       .forRoutes({path:'*',method:RequestMethod.ALL})
//   }
// }

export class AppModule{}